package com.fast.common.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * 作者：ylc
 * 时间：2018年5月28日09:57:27
 * 描述：线程池工具类
 */
public enum ThreadPoolUtil {
    INSTANCE;
    private  ExecutorService cachedThreadPool = null;
    private  ExecutorService fixedThreadPool = null;
    private  ScheduledExecutorService scheduledThreadPool = null;
    private  ExecutorService singleThreadPool = null;

    ThreadPoolUtil(){
        cachedThreadPool = Executors.newCachedThreadPool();
        fixedThreadPool = Executors.newFixedThreadPool(10);
        scheduledThreadPool = Executors.newScheduledThreadPool(10);
        singleThreadPool = Executors.newSingleThreadExecutor();
    }

    public ExecutorService getCachedThreadPool(Runnable runnable) {
        cachedThreadPool.submit(runnable);
        return cachedThreadPool;
    }

    public ExecutorService getFixedThreadPool(Runnable runnable) {
        fixedThreadPool.submit(runnable);
        return fixedThreadPool;
    }

    public ScheduledExecutorService getScheduledThreadPool(Runnable runnable) {
        scheduledThreadPool.submit(runnable);
        return scheduledThreadPool;
    }

    public ExecutorService getSingleThreadPool(Runnable runnable) {
        singleThreadPool.submit(runnable);
        return singleThreadPool;
    }
}
